//
//  XiuGaiViewController.m
//  ShangChengMoBan
//
//  Created by yaoqi yaoqi on 16/9/14.
//  Copyright © 2016年 ping. All rights reserved.
//

#import "XiuGaiViewController.h"

@interface XiuGaiViewController ()<UITextFieldDelegate>

@end

@implementation XiuGaiViewController
{
    UITextField * _oldPassword,* _new1Password,* _new2Password;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self drawNavWithTitle:@"修改密码" WithColor:[UIColor colorWithHue:0.00 saturation:0.00 brightness:1.00 alpha:1.00]];
    self.view.backgroundColor = [UIColor colorWithHue:0.69 saturation:0.02 brightness:0.96 alpha:1.00];
    [self drawBackButton];
    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 35+64, KScreenWidth, 40)];
    view.layer.borderWidth = 1 ;
    view.layer.borderColor = [UIColor colorWithHue:0.71 saturation:0.02 brightness:0.87 alpha:1.00].CGColor;
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    _oldPassword = [[UITextField alloc]initWithFrame:CGRectMake(15, 5, KScreenWidth-15, 30)];
    _oldPassword.delegate = self;
    _oldPassword.placeholder = @"请输入原密码";
    _oldPassword.font = [UIFont systemFontOfSize:13];
    [_oldPassword setSecureTextEntry:YES];
    [view addSubview:_oldPassword];
    UIView * view1 = [[UIView alloc]initWithFrame:CGRectMake(0, view.bottom+1, KScreenWidth, 40)];
    view1.layer.borderWidth = 1 ;
    view1.layer.borderColor = [UIColor colorWithHue:0.71 saturation:0.02 brightness:0.87 alpha:1.00].CGColor;
    view1.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view1];
    _new1Password = [[UITextField alloc]initWithFrame:CGRectMake(15, 5, KScreenWidth-15, 30)];
    _new1Password.delegate = self;
    _new1Password.placeholder = @"请设置新密码";
    _new1Password.font = [UIFont systemFontOfSize:13];
    [_new1Password setSecureTextEntry:YES];
    [view1 addSubview:_new1Password];
    UIView * view2 = [[UIView alloc]initWithFrame:CGRectMake(0, view1.bottom+1, KScreenWidth, 40)];
    view2.layer.borderWidth = 1 ;
    view2.layer.borderColor = [UIColor colorWithHue:0.71 saturation:0.02 brightness:0.87 alpha:1.00].CGColor;
    view2.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view2];
    _new2Password = [[UITextField alloc]initWithFrame:CGRectMake(15, 5, KScreenWidth-15, 30)];
    _new2Password.delegate = self;
    _new2Password.placeholder = @"再次输入密码";
    _new2Password.font = [UIFont systemFontOfSize:13];
    [_new2Password setSecureTextEntry:YES];
    [view2 addSubview:_new2Password];
    UIButton * xiaBu = [[UIButton alloc]initWithFrame:CGRectMake(20, view2.bottom+50, KScreenWidth-40, 35)];
    [xiaBu setTitle:@"完成" forState:UIControlStateNormal];
    xiaBu.titleLabel.font = [UIFont systemFontOfSize:14];
    xiaBu.backgroundColor = [UIColor colorWithHue:1.00 saturation:1.00 brightness:1.00 alpha:1.00];
    [xiaBu setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    xiaBu.layer.cornerRadius = 4;
    [xiaBu addTarget:self action:@selector(queDing) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:xiaBu];

}
-(void)queDing{
    if (_oldPassword.text.length == 0) {
        [[iToast makeText:@"  请输入原密码!  "] show];
        return;
    }
    if (_new2Password.text.length <6 || _new1Password.text.length < 6) {
        [[iToast makeText:@"  密码不得小于6位!  "] show];
        return;
    }
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
     [dic setObject:[self defaultLoadUserName] forKey:@"userName"];
     [dic setObject:_oldPassword.text forKey:@"oldPassword"];
     [dic setObject:_new1Password.text forKey:@"newPassword"];
    [dic setObject:_new2Password.text forKey:@"rPassword"];
    [NetWorking NEWjieKouQingQiu:XG_userUpdatePassword ANDIP:IP And:dic anBlock:^(NSDictionary *dic, NSError *error) {
        if (!error) {
            if ([dic[Code] intValue] == 200) {
                [TCUtils showAlertViewWithTitle:@"提示" message:@"修改成功" delegate:self cancel:@"确定" other:nil tag:777];
                [self.navigationController popViewControllerAnimated:YES];
            }
        }
    }];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    if([textField isEqual:_oldPassword]){
        [_new1Password becomeFirstResponder];
    }else if([textField isEqual:_new1Password]){
        [_new2Password becomeFirstResponder];
    }else{
        [textField endEditing:YES];
    }
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
